package it.uniroma2.mpsr.utils;

import it.uniroma2.mpsr.resources.State;

public class Permutations {
	
	private State[] states;
	private int index;
	
	public Permutations(int Ns) {
		this.states = new State[Ns];
		this.index = Ns-1;
	}

	public void generatePermutations(int N, int[] n, int idx) {
		if (idx == n.length) {  //stop condition for the recursion [base clause]
			int sum = 0;
			for(int i = 0; i < n.length; i++) {
				sum += n[i];
			}
			if(sum == N) {
				states[index] = new State(n);
				index--;
			}
			return;
		}
		for (int i = 0; i <= N; i++) { 
			n[idx] = i;
			generatePermutations(N, n, idx+1); //recursive invokation, for next elements
		}
	}

	public State[] getStates() {
		return states;
	}
	
}
